using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The NationalityCodeTableManager class is responsible for managing BO.NationalityCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class NationalityCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all NationalityCodeTable objects in the database.
/// </summary>
/// <returns>A list with all NationalityCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static NationalityCodeTableList GetList(){
return NationalityCodeTableDB.GetList();
}

/// <summary>
/// Gets a single NationalityCodeTable from the database without its data.
/// </summary>
/// <param name="nationalityCode">The NationalityCode of the NationalityCodeTable in the database.</param>
/// <returns>A NationalityCodeTable object when the NationalityCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static NationalityCodeTable GetItem(short nationalityCode,int SchoolKey){
return GetItem(nationalityCode,SchoolKey, false);
}

/// <summary>
/// Gets a single NationalityCodeTable from the database.
/// </summary>
/// <param name="nationalityCode">The NationalityCode of the NationalityCodeTable in the database.</param>
/// <param name="getNationalityCodeTableRecords">Determines whether to load all associated NationalityCodeTable records as well.</param>
/// <returns>
/// A NationalityCodeTable object when the NationalityCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static NationalityCodeTable GetItem(short nationalityCode,int SchoolKey, bool getNationalityCodeTableRecords){
NationalityCodeTable myNationalityCodeTable = NationalityCodeTableDB.GetItem(nationalityCode);
if (myNationalityCodeTable != null && getNationalityCodeTableRecords){
myNationalityCodeTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByNationalityCode(nationalityCode);
}
if (myNationalityCodeTable != null && getNationalityCodeTableRecords){
myNationalityCodeTable.guardianProfileTables = GuardianProfileTableDB.GetListByNationalityCode(nationalityCode);
}
if (myNationalityCodeTable != null && getNationalityCodeTableRecords){
myNationalityCodeTable.studentProfileTables = StudentProfileTableDB.GetListByNationalityCode(nationalityCode);
}
if (myNationalityCodeTable != null && getNationalityCodeTableRecords){
myNationalityCodeTable.teacherProfileTables = TeacherProfileTableDB.GetListByNationalityCode(nationalityCode,SchoolKey);
}
if (myNationalityCodeTable != null && getNationalityCodeTableRecords){
myNationalityCodeTable.userProfileTables = UserProfileTableDB.GetListByNationalityCode(nationalityCode);
}
return myNationalityCodeTable;
}

/// <summary>
/// Saves a NationalityCodeTable in the database.
/// </summary>
/// <param name="myNationalityCodeTable">The NationalityCodeTable instance to save.</param>
/// <returns>The new NationalityCode if the NationalityCodeTable is new in the database or the existing NationalityCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(NationalityCodeTable myNationalityCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short nationalityCodeTableNationalityCode = NationalityCodeTableDB.Save(myNationalityCodeTable);
foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myNationalityCodeTable.familyMemberProfileTables){
myFamilyMemberProfileTable.NationalityCode = nationalityCodeTableNationalityCode;
FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
}
foreach (GuardianProfileTable myGuardianProfileTable in myNationalityCodeTable.guardianProfileTables){
myGuardianProfileTable.NationalityCode = nationalityCodeTableNationalityCode;
GuardianProfileTableDB.Save(myGuardianProfileTable);
}
foreach (StudentProfileTable myStudentProfileTable in myNationalityCodeTable.studentProfileTables){
myStudentProfileTable.NationalityCode = nationalityCodeTableNationalityCode;
StudentProfileTableDB.Save(myStudentProfileTable);
}
foreach (TeacherProfileTable myTeacherProfileTable in myNationalityCodeTable.teacherProfileTables){
myTeacherProfileTable.NationalityCode = nationalityCodeTableNationalityCode;
TeacherProfileTableDB.Save(myTeacherProfileTable);
}
foreach (UserProfileTable myUserProfileTable in myNationalityCodeTable.userProfileTables){
myUserProfileTable.NationalityCode = nationalityCodeTableNationalityCode;
UserProfileTableDB.Save(myUserProfileTable);
}

//  Assign the NationalityCodeTable its new (or existing NationalityCode).
myNationalityCodeTable.NationalityCode = nationalityCodeTableNationalityCode;

myTransactionScope.Complete();

return nationalityCodeTableNationalityCode;
}
}

/// <summary>
/// Deletes a NationalityCodeTable from the database.
/// </summary>
/// <param name="myNationalityCodeTable">The NationalityCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(NationalityCodeTable myNationalityCodeTable){
return NationalityCodeTableDB.Delete(myNationalityCodeTable.NationalityCode);
}

#endregion

}

}
